//注册验证
(function($) {
	var bStop1 = false;
	var bStop2 = false;
	var bStop3 = false;
	var bStop4 = false;
	var bStop5 = false;
	var username_reg = /^([\w]|[u4E00-u9FA5]){3,15}$/;
	$('#username').on('blur', function() {
		var username_val = $('#username').val();
		if(username_reg.test(username_val)) {
			$.ajax({
					type: "post",
					url: "../php/register.php",
					async: true,
					data: {
						name: username_val
					}
				})
				.done(function(data) {
					if(!data) {
						$('#username_tips').html('√');
						bStop1 = true;
					} else {
						$('#username_tips').html('该用户名已被注册过！');
					}
				})
				.fail(function(xhr, err) {
					console.log(xhr + ',' + err);
				});

		} else {
			$('#username_tips').html('您输入的用户名格式不符合规范!请重新输入...');
			bStop1 = false;
		}
		if(username_val == '') {
			$('#username_tips').html('用户名不能为空!');
			bStop1 = false;
		}

	});
	var pw_reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/;
	var pw_val = null;
	$('#pw').on('blur', function() {
		pw_val = $('#pw').val();
		if(pw_reg.test(pw_val)) {
			$('#pw_tips').html('√');
			bStop2 = true;

		} else {
			$('#pw_tips').html('您输入的密码格式不符合规范，请重新输入...');
			bStop2 = false;
		}
		if(pw_val == '') {
			$('#pw_tips').html('密码不能为空!');
			bStop2 = false;
		}
	});
	$('#pw_confirm').on('blur', function() {
		var pwconfirm_val = $('#pw_confirm').val();
		if(pw_val == pwconfirm_val) {
			$('#pwconfirm_tips').html('√');
			bStop3 = true;
		} else {
			$('#pwconfirm_tips').html('请保持与第一次输入的密码一致！');
			bStop3 = false;
		}
		if(pwconfirm_val == '') {
			$('#pwconfirm_tips').html('密码不能为空!');
			bStop3 = false;
		}
	});
	var email_reg = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
	$('#email').on('blur', function() {
		var email_val = $('#email').val();
		if(email_reg.test(email_val)) {
			$('#email_tips').html('√');
			bStop4 = true;

		} else {
			$('#email_tips').html('您输入的邮箱格式不符合规范!请重新输入...');
			bStop4 = false;
		}
		if(email_val == '') {
			$('#email_tips').html('邮箱不能为空!');
			bStop4 = false;
		}
	});
	
	$('.register #ck').on('click', function() {
		if($('.register #ck').is(':checked')) {
			bStop5 = true;
		} else {
			bStop5 = false;
		}
	})

	$('form').on('submit', function() {
		console.log(bStop1, bStop2, bStop3, bStop4, bStop5);
		if(bStop1 == false || bStop2 == false || bStop3 == false || bStop4 == false || bStop5 == false) {
			return false;
		}
	});
})(jQuery);